mod counter;
mod hu_man;
fn main() {
    //定长数组
    let mut arr_1: [u8; 3] = [1, 8, 4];
    println!("{:?}", arr_1);
    arr_sort(&mut arr_1);
    println!("{:?}", arr_1);
    //不定长数组
    //调用
    let person = Person {
        name: String::from("张三"),
        age: 54,
        add: String::from("湖南省"),
    };
    person.broken();
    person.say();
    let fu = Some(100);
    println!("{:?}", fu);
    //
    let man = hu_man::HuMan::new(String::from("李四"), 30);
    println!("{}", man.say());
    let v1 = vec![1, 3, 8, 2, 0, -20, 90, -9000, 0];
    println!("{:?}中最大的数是:{}", &v1, largest(&v1));
    //静态变量,直接变成可变静态变量需要使用unsafe关键字，意味着不是安全操作
    let mut counter = unsafe { counter::COUNTER + 10 };
    println!("{}", counter);
    counter += 2;

    println!("{}", counter);

    println!("{}+{}={}", 5, 4, add(5, 4));
}

fn arr_sort(arr: &mut [u8]) -> &[u8] {
    arr.sort();
    arr
}

#[allow(dead_code)]
struct Person {
    name: String,
    age: u8,
    add: String,
}

trait Action {
    fn say(&self);
    fn broken(&self);
}

impl Person {
    fn say(&self) {
        println!("{} can say", &self.name);
    }
    fn broken(&self) {
        println!("{} can broken", self.name);
    }
}

//为泛型函数限制类型,并不是所有的类型都能比大小, 只有i32和Char实现了PartialOrd特性
fn largest<T: std::cmp::PartialOrd + Copy>(list: &[T]) -> T {
    let mut result = list[0];
    for &item in list.into_iter() {
        if item > result {
            result = item;
        }
    }
    result
}

fn add<T: std::ops::Add<Output = T>>(m: T, n: T) -> T {
    m + n
}
